﻿using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;

public class EcoMUVEDataMgr
{
    private static EcoMUVEDataMgr s_pInstance;

    public static EcoMUVEDataMgr Instance
    {
        get
        {
            if (null == s_pInstance)
            {
                s_pInstance = new EcoMUVEDataMgr();
            }
            return s_pInstance;
        }
    }
    private EcoMUVEDataTable dataTable = new EcoMUVEDataTable();
    private EcoMUVEDataStatusTable dataStatusTable = new EcoMUVEDataStatusTable();

    // 加载EcoMUVE数据表和数据状态表（是否已经采集）
    public void LoadData()
    {
        string dataPath = Application.dataPath + "/CSV2Table/Demo/EcoMUVEData.csv";
        string statusPath = Application.dataPath + "/CSV2Table/Demo/EcoMUVEDataStatus.csv";

        dataTable.Load(dataPath);        
        dataStatusTable.Load(statusPath);        
    }


    // 保存EcoMUVE数据状态表
    public void SaveStatus()
    {
        if (dataStatusTable == null)
        {
            Debug.LogError("dataStatusTable is null");
            return;
        }
        string statusPath = Application.dataPath + "/CSV2Table/Demo/EcoMUVEDataStatus.csv";
        dataStatusTable.Save(statusPath);
    }

    // 获取数据表中的所有内容
    public List<EcoMUVEDataTable.Row> GetAllData()
    {
        return dataTable.GetRowList();
    }

    // 获取数据状态表的所有内容
    public List<EcoMUVEDataStatusTable.Row> GetAllDataStatus()
    {
        return dataStatusTable.GetRowList();
    }

    // 根据日期返回数据
    public EcoMUVEDataTable.Row GetDataByDate(string date)
    {
        return dataTable.Find_Date(date);
    }

    // 根据日期返回状态数据
    public EcoMUVEDataStatusTable.Row GetStatusByDate(string date)
    {
        return dataStatusTable.Find_Date(date);
    }

}
